import Vue from 'vue'
import Router from 'vue-router'

// import Test from '@/components/test.vue'
// import imageUpload from '@/components/imageUpload.vue'

import Login from '@/components/Login.vue'
import Home from '@/components/Home.vue'

import Report from '@/components/report/Report.vue'
import UserReport from '@/components/report/UserReport.vue'
import MilkTeaVolume from '@/components/report/MilkTeaVolume.vue'
import CommodityVolume from '@/components/report/CommodityVolume.vue'

import Users from '@/components/user/Users.vue'
import UserRecharge from '@/components/user/UserRecharge.vue'
import UserConsume from '@/components/user/UserConsume.vue'


import Store from '@/components/settings/Store.vue'
import Staff from '@/components/settings/Staff.vue'
import AddStaff from '@/components/settings/AddStaff.vue'
import UpStaff from '@/components/settings/UpStaff.vue'
import Carousel from '@/components/settings/Carousel.vue'
import AddCarousel from '@/components/settings/AddCarousel.vue'
import UpCarousel from '@/components/settings/UpCarousel.vue'
import Activity from '@/components/settings/Activity.vue'
import AddActivity from '@/components/settings/AddActivity.vue'
import UpActivity from '@/components/settings/UpActivity.vue'
import Recommend from '@/components/settings/Recommend.vue'
import AddRecommend from '@/components/settings/AddRecommend.vue'
import UpRecommend from '@/components/settings/UpRecommend.vue'
import Member from '@/components/settings/Member.vue'


import Commodity from '@/components/goods/Commodity.vue'
import AddCommodity from '@/components/goods/AddCommodity.vue'
import UpCommodity from '@/components/goods/UpCommodity.vue'
import MoreCommodity from '@/components/goods/MoreCommodity.vue'
import CommodityType from '@/components/goods/CommodityType.vue'
import AddCommodityType from '@/components/goods/AddCommodityType.vue'
import UpCommodityType from '@/components/goods/UpCommodityType.vue'
import MoreCommodityType from '@/components/goods/MoreCommodityType.vue'
import Flavor from '@/components/goods/Flavor.vue'

import MilkyTea from '@/components/milky_tea/MilkyTea.vue'
import AddMilkyTea from '@/components/milky_tea/AddMilkyTea.vue'
import UpMilkyTea from '@/components/milky_tea/UpMilkyTea.vue'
import MoreMilkyTea from '@/components/milky_tea/MoreMilkyTea.vue'
import MilkyTeaType from '@/components/milky_tea/MilkyTeaType.vue'
import AddMilkyTeaType from '@/components/milky_tea/AddMilkyTeaType.vue'
import UpMilkyTeaType from '@/components/milky_tea/UpMilkyTeaType.vue'
import MoreMilkyTeaType from '@/components/milky_tea/MoreMilkyTeaType.vue'
import Material from '@/components/milky_tea/Material.vue'
import Sweetness from '@/components/milky_tea/Sweetness.vue'
import Temperature from '@/components/milky_tea/Temperature.vue'

import Order from '@/components/order/Order.vue'
import MoreOrder from '@/components/order/MoreOrder.vue'
import OrderUser from '@/components/order/OrderUser.vue'

import Coupon from '@/components/coupon/Coupon.vue'
import AddCoupon from '@/components/coupon/AddCoupon.vue'
import UpCoupon from '@/components/coupon/UpCoupon.vue'

import Wallet from '@/components/wallet/Wallet.vue'

import Recharge from '@/components/recharge/Recharge.vue'

import Consume from '@/components/consume/Consume.vue'

import StaffEvaluate from '@/components/evaluate/StaffEvaluate.vue'



Vue.use(Router)

const router = new Router({
  routes: [
    { path: '/', redirect: '/login' },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/home',
      name: 'Home',
      component: Home,
      children: [
        // {path:'/test',component: Test},
        // {path:'/upload',component: imageUpload},
        { path: '/report', component: Report },
        { path: '/userReport', component: UserReport },
        { path: '/milkTeaVolume', component: MilkTeaVolume },
        { path: '/commodityVolume', component: CommodityVolume },

        { path: '/store', component: Store },
        { path: '/staff', component: Staff },
        { path: '/staff/addStaff', component: AddStaff },
        { path: '/staff/upStaff/:id', component: UpStaff },
        { path: '/carousel', component: Carousel },
        { path: '/carousel/addCarousel', component: AddCarousel },
        { path: '/carousel/upCarousel/:id', component: UpCarousel },
        { path: '/activity', component: Activity },
        { path: '/activity/addActivity', component: AddActivity },
        { path: '/activity/upActivity/:id', component: UpActivity },
        { path: '/recommend', component: Recommend },
        { path: '/recommend/addRecommend', component: AddRecommend },
        { path: '/recommend/upRecommend/:id', component: UpRecommend },
        { path: '/member', component: Member },

        { path: '/commodity', component: Commodity },
        { path: '/commodity/addCommodity', component: AddCommodity },
        { path: '/commodity/upCommodity/:id', component: UpCommodity },
        { path: '/commodity/moreCommodity/:id/:fromUrl/:typeId', component: MoreCommodity},
        { path: '/commodityType', component: CommodityType},
        { path: '/commodityType/addCommodityType', component: AddCommodityType},
        { path: '/commodityType/upCommodityType/:id', component: UpCommodityType},
        { path: '/commodityType/moreCommodityType/:id', component: MoreCommodityType},
        { path: '/flavor', component: Flavor},

        { path: '/milkyTea', component: MilkyTea},
        { path: '/milkyTea/addMilkyTea', component: AddMilkyTea},
        { path: '/milkyTea/upMilkyTea/:id', component: UpMilkyTea},
        { path: '/milkyTea/moreMilkyTea/:id/:fromUrl/:typeId', component: MoreMilkyTea},
        { path: '/milkyTeaType', component: MilkyTeaType},
        { path: '/milkyTeaType/addMilkyTeaType', component: AddMilkyTeaType},
        { path: '/milkyTeaType/upMilkyTeaType/:id', component: UpMilkyTeaType},
        { path: '/milkyTeaType/moreMilkyTeaType/:id', component: MoreMilkyTeaType},
        { path: '/material', component: Material},
        { path: '/sweetness', component: Sweetness},
        { path: '/temperature', component: Temperature},

        { path: '/order', component: Order },
        { path: '/order/moreOrder/:id', component: MoreOrder },
        { path: '/order/orderUser/:id', component: OrderUser },

        {path: '/users',component: Users},
        {path: '/users/userRecharge/:id/:fromUrl',component: UserRecharge},
        {path: '/users/userConsume/:id/:fromUrl',component: UserConsume},


        { path: '/coupon', component: Coupon },
        { path: '/coupon/addCoupon', component: AddCoupon },
        { path: '/coupon/upCoupon/:id', component: UpCoupon },

        { path: '/wallet', component: Wallet},
        
        { path: '/recharge', component: Recharge},

        { path: '/consume', component: Consume},

        { path: '/evaluate', component: StaffEvaluate},


      ]
    },
  ]
})

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  //     next()  放行    next('/login')  强制跳转

  if (to.path === '/login') return next()
  // 获取token
  const tokenStr = window.localStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

export default router